﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace trunk.Views
{
    /// <summary>
    /// HomePage.xaml 的交互逻辑
    /// </summary>
    public partial class HomePage : Page
    {
        public HomePage()
        {
            InitializeComponent();
            InitializeCommand();
        }

        private RoutedCommand EnterCommand = new RoutedCommand();

        private void InitializeCommand()
        {
            //this.CommandBindings.Add(new CommandBinding(EnterCommand, EnterExecuted, EnterCanExecute));
            //EnterButton.Command = EnterCommand;
            CommandBinding cb = new CommandBinding(EnterCommand);
            cb.Executed += EnterExecuted;
            cb.CanExecute += EnterCanExecute;
            this.CommandBindings.Add(cb);
            EnterButton.Command = EnterCommand;
        }

        public void EnterExecuted(object parameter, ExecutedRoutedEventArgs e)
        {
            //写法1
            MainPage mp = new MainPage();
            //this.NavigationService.Navigate(mp);
            //或
            this.NavigationService.Content = mp;

            //写法2
            //this.NavigationService.Navigate(new Uri("Views/MainPage.xaml",UriKind.Relative));
            //或
            //this.NavigationService.Source = new Uri("Views/MainPage.xaml", UriKind.Relative);
        }

        public void EnterCanExecute(object parameter, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

    }
}
